package edu.pku.sei.modeler.uml.commands;

import edu.pku.sei.modeler.model.core.MetaModelElement;
import edu.pku.sei.modeler.model.uml.Kernel.Classifier;
import edu.pku.sei.modeler.model.uml.Kernel.Generalization;

public class UMLGeneralizaitonDeleteCommand extends
		ConnectionModelDeleteCommand {

	public UMLGeneralizaitonDeleteCommand(MetaModelElement connectionModel,
			MetaModelElement sourceModel, MetaModelElement targetModel) {
		super(connectionModel, sourceModel, targetModel);
		// TODO Auto-generated constructor stub
	}

	@Override
	public boolean canExecute() {
		if (sourceModel instanceof Classifier
				&& targetModel instanceof Classifier) {
			return true;
		}

		return false;
	}

	@Override
	public void execute() {
		Classifier sourceClassifer = (Classifier) this.sourceModel;
		Generalization generalization = (Generalization) this.connectionModel;
		sourceClassifer.getGeneralization().remove(generalization);
		sourceClassifer.getGeneral().remove(targetModel);
	}

	@Override
	public void undo() {
		Classifier sourceClassifer = (Classifier) this.sourceModel;
		Generalization generalization = (Generalization) this.connectionModel;

		sourceClassifer.getGeneralization().add(generalization);
		sourceClassifer.getGeneral().add(targetModel);
		generalization.setContainer(sourceClassifer);
		generalization.setModel(sourceClassifer.getModel());
	}

}
